<template>
  <div style="padding: 6px;">
    <el-form ref="searchForm" label-width="100px">
      <el-row :gutter="20">
        <el-col :span="4">
          <el-form-item label="消息类型">
            <el-input v-model="sd.typeName" size="small" placeholder="消息类型" />
          </el-form-item>
        </el-col>
<!--        <el-col :span="4">-->
<!--          <el-form-item label="订单内容">-->
<!--            <el-input v-model="sd.orderData" size="small" placeholder="订单内容" />-->
<!--          </el-form-item>-->
<!--        </el-col>-->
        <el-col :span="4">
          <el-form-item label="开始日期">
            <el-date-picker v-model="sd.startDate" type="date" placeholder="开始日期" value-format="yyyy-MM-dd" />
          </el-form-item>
        </el-col>
        <el-col :span="4">
          <el-form-item label="结束日期">
            <el-date-picker v-model="sd.endDate" type="date" placeholder="结束日期" value-format="yyyy-MM-dd" />
          </el-form-item>
        </el-col>
        <el-col :span="3">
          <el-button class="mt_5" type="primary" size="mini" icon="el-icon-search" @click="searchSrmData">查询</el-button>
        </el-col>
      </el-row>
    </el-form>
    <el-table :data="srmDataObj.list" border style="width: 100%">
      <el-table-column label="消息ID" prop="orderid" width="120px"></el-table-column>
      <el-table-column label="消息类型" prop="typename" width="400px"></el-table-column>
<!--      <el-table-column label="处理状态" prop="statusname"></el-table-column>-->
      <el-table-column label="消息内容" prop="msgdata"></el-table-column>
      <el-table-column label="错误内容" prop="errormsg"></el-table-column>
      <el-table-column label="创建日期" width="150px">
        <template v-slot="scope">
          <DateFormat :value="scope.row.createtime" :format="'YYYY-MM-DD HH:mm'"></DateFormat>
        </template>
      </el-table-column>
      <el-table-column label="操作" width="220px">
        <template v-slot="scope">
          <el-button size="mini" type="primary" @click="viewSrmMsg(scope.row.orderdata)">查看订单内容</el-button>
          <el-button size="mini" type="warning" @click="processSrmMsg(scope.row.id)">重处理</el-button>
        </template>
      </el-table-column>
    </el-table>
    <el-pagination v-if="srmDataObj.total>sd.pageSize" class="center" background layout="total, prev, pager, next"
                   @current-change="loadSrmData" :total="srmDataObj.total"
                   :current-page.sync="sd.pageNum" :page-size="sd.pageSize">
    </el-pagination>
    <el-dialog title="订单内容" :visible.sync="viewMsgVisible" :close-on-click-modal="false" width="1100px">
      <JsonViewer :value="viewJsonData" :expand-depth="expand"></JsonViewer>
    </el-dialog>
  </div>
</template>

<script>
import request from '@/utils/request'
import JsonViewer  from 'vue-json-viewer'
export default {
  components:{JsonViewer},
  data() {
    return {
      sd: {
        typeName:'',
        orderData:'',
        startDate:'',
        endDate:'',
        pageNum: 1,
        pageSize: 10
      },
      srmDataObj: {},
      viewJsonData:{},
      expand:5,

      viewMsgVisible : false,
      popupEntityId : 0,
    }
  },
  mounted() {
    this.loadSrmData()
  },
  methods: {
    searchSrmData(){
      this.sd.pageNum= 1;
      this.loadSrmData();
    },
    loadSrmData() {
      request({
        url: '/srmmsg/listerrorsrmmessage',
        data: this.sd
      }).then(res => {
        const { data } = res
        this.srmDataObj = data
      })
    },
    viewSrmMsg(jsonData){
      this.viewMsgVisible= true
      this.viewJsonData= JSON.parse(jsonData);
    },
    processSrmMsg(id){
      request({
        url: '/srmmsg/processerrorsrmmessage',
        data: {id:id}
      }).then(res => {
        if(res.code === "200"){
          this.$message.success("处理成功")
          this.loadSrmData();
        }else{
          this.$message.success(res.msg)
        }
      })
    },
  }
}
</script>
